package com.naiterui.ehp.bs.emr.vo.health;

import cn.hutool.core.collection.CollectionUtil;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.utils.date.DateUtil;
import com.naiterui.ehp.bs.emr.exception.ExceptionCodes;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * @Description 慢病史
 * @Author gongbaoqiang
 * @Date 2020/6/2 2:26 PM
 */
@Data
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("慢病史")
public class ChronicVO implements Serializable {
    private static final long serialVersionUID = -5101703092988238908L;

    /**
     * 选项值
     */
    @ApiModelProperty("慢病值")
    private List<String> values;

    /**
     * 糖尿病
     */
    @ApiModelProperty("糖尿病")
    private ChronicDetailVO diabetes;

    /**
     * 冠心病
     */
    @ApiModelProperty("冠心病")
    private ChronicDetailVO conronaryHeart;

    /**
     * 甲亢
     */
    @ApiModelProperty("甲亢")
    private ChronicDetailVO thyroidism;


    /**
     * 甲减
     */
    @ApiModelProperty("甲减")
    private ChronicDetailVO hypothyroidism;

    /**
     * 慢性肾病
     */
    @ApiModelProperty("慢性肾病")
    private ChronicDetailVO nephropathy;


    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class ChronicDetailVO implements Serializable {

        private static final long serialVersionUID = -162895910466113204L;
        /**
         * 类型
         */
        @ApiModelProperty("类型")
        private String type;

        /**
         * 确诊日期
         */
        @ApiModelProperty("确诊日期")
        @JsonFormat(pattern = DateUtil.DATE_FORMAT)
        private Date diagnosisDate;

        /**
         * 现阶段治疗方案
         */
        @ApiModelProperty("现阶段治疗方案")
        private List<String> treatmentPlan;

        public void validate() throws BusinessException {
            if (StringUtils.isBlank(this.type) || this.diagnosisDate == null || CollectionUtil.isEmpty(this.treatmentPlan)) {
                throw new BusinessException(ExceptionCodes.PATIENT_HEALTH_RECORD_CHRONIC);
            }
        }

    }

    public void validate() throws BusinessException {
        if (CollectionUtil.isEmpty(this.values)) {
            throw new BusinessException(ExceptionCodes.PATIENT_HEALTH_RECORD_CHRONIC);
        }
        if (this.values.contains("糖尿病")) {
            this.diabetes.validate();
        }
        if (this.values.contains("冠心病")) {
            this.conronaryHeart.validate();
        }
        if (this.values.contains("甲亢")) {
            this.thyroidism.validate();
        }
        if (this.values.contains("甲减")) {
            this.hypothyroidism.validate();
        }
        if (this.values.contains("慢性肾病")) {
            this.nephropathy.validate();
        }
    }
}
